/*****************************************************************************

File:   otkDeleteLayerStateExample.java

Date          Build     Author        Version    Comments
18-Sep-12    P-20-14    dshah          $$1        Created
17-Oct-12    P-20-15    dshah          $$2        Updated
20-mar-15 P-30-05 gshmelev $$3  called GetCurrentSession

****************************************************************************/

/* 
   
Example for layer state.

*/

package com.ptc.otkjavaexamples;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcLayerState.*;


//Deletes layer state
class otkDeleteLayerStateExample extends DefaultUICommandActionListener
{
    
    
    
    public otkDeleteLayerStateExample()
    {
    }
    
    
    
    
    public void OnCommand()
    {
	addDeleteLayerStateExample();
    }
    
    
    public int addDeleteLayerStateExample()
    {
	try
	    {
		
		FileWriter file = new FileWriter ("LayerState_info.txt");
		BufferedWriter fp_out_layerstate = new BufferedWriter(file);
		
		Session session = pfcSession.GetCurrentSession ();
		WSolid WSolid = (WSolid)(session.GetCurrentModel());
		
		LayerStates WLayerStates1 =   WSolid.ListLayerStates();
		int LayerStatesArraySize1 = WLayerStates1.getarraysize ();
		
		fp_out_layerstate.write("=======================");
		fp_out_layerstate.newLine();
		fp_out_layerstate.write("- Layer State Example -");
		fp_out_layerstate.newLine();
		fp_out_layerstate.write("=======================");
		fp_out_layerstate.newLine();
		fp_out_layerstate.newLine();
		
		LayerState WLayerState = otkLayerStateUtils.otkUtilSelectLayerState(WSolid, (int) -1);
		
		fp_out_layerstate.write("**** Before Deleting Layer State ****");
		fp_out_layerstate.newLine();
		fp_out_layerstate.newLine();
		fp_out_layerstate.write("List of layer states:");
		fp_out_layerstate.newLine();
		fp_out_layerstate.newLine();
		
		for(int i=0; i<LayerStatesArraySize1; i++)
		{
			LayerState WLayerState1 = WLayerStates1.get(i);
			fp_out_layerstate.write("-" + WLayerState1.GetName());
			fp_out_layerstate.newLine();
		}
		
		if(WLayerState != null)
		    otkLayerStateUtils.otkUtilDeleteLayerState(WLayerState);
			
		LayerStates WLayerStates2 =   WSolid.ListLayerStates();
		int LayerStatesArraySize2 = WLayerStates2.getarraysize ();
			
		fp_out_layerstate.newLine();
		fp_out_layerstate.write("**** After Deleting Layer State ****");
		fp_out_layerstate.newLine();
		fp_out_layerstate.newLine();
		fp_out_layerstate.write("List of layer states:");
		fp_out_layerstate.newLine();
		fp_out_layerstate.newLine();
		
		for(int i=0; i<LayerStatesArraySize2; i++)
		{
			LayerState WLayerState2 = WLayerStates2.get(i);
			fp_out_layerstate.write("-" + WLayerState2.GetName());
			fp_out_layerstate.newLine();
		}
		
		fp_out_layerstate.close();
		return (0);		
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	return (0);
    }
    
};






